package redora.rdo.configuration.rdo.service;

import java.util.Date;
import java.util.Set;

import org.apache.commons.codec.digest.DigestUtils;

import redora.rdo.api.BusinessRuleViolation;
import redora.rdo.exceptions.BusinessRuleViolationException;
import redora.rdo.configuration.rdo.service.base.RedoraTrashBusinessRulesBase;
import redora.rdo.configuration.rdo.model.RedoraTrash;

public class RedoraTrashBusinessRules extends RedoraTrashBusinessRulesBase {
	public RedoraTrashBusinessRules() {
	
	}
	
	/**
	 * Set the undoHash when it is empty
	 */
	@Override
	public Set<BusinessRuleViolation> onInsert(RedoraTrash pojo) throws BusinessRuleViolationException {
		//Set undoHash before checking the business rules
		if (pojo.getUndoHash() == null) {
			//StringBuilder is about 25% faster in JDK1.6
			pojo.setUndoHash(DigestUtils.shaHex(
					new StringBuilder(pojo.getObjectName())
					.append(pojo.getObjectId())
					.append(new Date()).toString()));
		}
		Set<BusinessRuleViolation> retval = super.onInsert(pojo);

		return retval;
	}
	
	@Override
	public Set<BusinessRuleViolation> onUpdate(RedoraTrash pojo) throws BusinessRuleViolationException {
		Set<BusinessRuleViolation> retval = super.onUpdate(pojo);
		
		return retval;
	}
	
	@Override
	public Set<BusinessRuleViolation> onDelete(RedoraTrash pojo) throws BusinessRuleViolationException {
		Set<BusinessRuleViolation> retval = super.onDelete(pojo);
		
		return retval;
	}
}